<?php
	//左侧菜单
	require '../biz/backend.php';

	class action extends backend
	{
		var $get_privilege_id = 3;

		function do_get()
		{
			$menu_array = array();
			$menu_array['setup'] = array( 'name' => '基本设置', 'privilege' => '92', 'item' => array() );
			$menu_array['setup']['item'][] = array( 'name' => '参数列表', 'url' => 'list_argument.php', 'privilege' => '93', 'target' => 'right' );
			$menu_array['setup']['item'][] = array( 'name' => '参数类型', 'url' => 'list_argument_type.php', 'privilege' => '94', 'target' => 'right' );

			$menu_array['column'] = array( 'name' => '栏目管理', 'privilege' => '81', 'item' => array() );
			$menu_array['column']['item'][] = array( 'name' => '栏目列表', 'url' => 'list_column.php', 'privilege' => '86', 'target' => 'right' );

			$menu_array['template'] = array( 'name' => '模板管理', 'privilege' => '82', 'item' => array() );
			$menu_array['template']['item'][] = array( 'name' => '模板列表', 'url' => 'list_tpl.php', 'privilege' => '87', 'target' => 'right' );
			$menu_array['template']['item'][] = array( 'name' => '标签管理', 'url' => 'list_tag.php', 'privilege' => '100', 'target' => 'right' );

			$menu_array['content'] = array( 'name' => '内容管理', 'privilege' => '83', 'item' => array() );
			$menu_array['content']['item'][] = array( 'name' => '内容列表', 'url' => 'list_html.php', 'privilege' => '88', 'target' => 'right' );

			$menu_array['publish'] = array( 'name' => '内容发布', 'privilege' => '97', 'item' => array() );
			$menu_array['publish']['item'][] = array( 'name' => '生成页面', 'url' => 'generate_html.php', 'privilege' => '96', 'target' => 'right' );
			//$menu_array['publish']['item'][] = array( 'name' => '发布页面', 'url' => 'publish_html.php', 'privilege' => '96', 'target' => 'right' );

			//$menu_array['widget'] = array( 'name' => '小应用管理', 'privilege' => '84', 'item' => array() );
			//$menu_array['widget']['item'][] = array( 'name' => '小应用列表', 'url' => 'list_widget.php', 'privilege' => '89', 'target' => 'right' );

			//$menu_array['tool'] = array( 'name' => '工具', 'privilege' => '85', 'item' => array() );
			//$menu_array['tool']['item'][] = array( 'name' => '备份', 'url' => 'tool_backup.php', 'privilege' => '90', 'target' => 'right' );
			//$menu_array['tool']['item'][] = array( 'name' => '还原', 'url' => 'tool_restore.php', 'privilege' => '91', 'target' => 'right' );

			$menu_array['system'] = array( 'name' => '系统管理', 'privilege' => '60', 'item' => array() );
			$menu_array['system']['item'][] = array( 'name' => '操作日志', 'url' => 'list_operate_log.php', 'privilege' => '61', 'target' => 'right' );
			$menu_array['system']['item'][] = array( 'name' => '内部帐户', 'url' => 'list_admin.php', 'privilege' => '62', 'target' => 'right' );
			$menu_array['system']['item'][] = array( 'name' => '权限类型', 'url' => 'list_privilege_type.php', 'privilege' => '65', 'target' => 'right' );
			$menu_array['system']['item'][] = array( 'name' => '权限列表', 'url' => 'list_privilege.php', 'privilege' => '66', 'target' => 'right' );
			$menu_array['system']['item'][] = array( 'name' => '帐户角色', 'url' => 'list_role.php', 'privilege' => '67', 'target' => 'right' );
			$menu_array['system']['item'][] = array( 'name' => '系统参数', 'url' => 'list_config.php', 'privilege' => '68', 'target' => 'right' );


			$database = load( 'database' );
			$temp = $database->select( 'select role_privilege.privilege_id from account, role_privilege where account.id = ' . $this->account_info['id'] . ' and account.role_id = role_privilege.role_id' );
			$privilege_array = array();
			foreach( $temp as $value ) $privilege_array[$value['privilege_id']] = '';

			foreach( $menu_array as $key => $data )
			{
				if ( is_numeric( $data['privilege'] ) )
				{
					if ( isset( $privilege_array[$data['privilege']] ) )
					{
						foreach( $data['item'] as $index => $value )
						{
							if ( is_numeric( $value['privilege'] ) )
							{
								if ( isset( $privilege_array[$value['privilege']] ) )
								{
									//has privilege
								}
								else
								{
									unset( $menu_array[$key]['item'][$index] );
								}
							}
							else
							{
								//not set privilege
							}
						}
					}
					else
					{
						unset( $menu_array[$key] );
					}
				}
				else
				{
					//not set privilege

					foreach( $data['item'] as $index => $value )
					{
						if ( is_numeric( $value['privilege'] ) )
						{
							if ( isset( $privilege_array[$value['privilege']] ) )
							{
								//has privilege
							}
							else
							{
								unset( $menu_array[$key]['item'][$index] );
							}
						}
						else
						{
							//not set privilege
						}
					}
				}
			}

			$template = load( 'template', array( 'domain'=>'tpl.admin' ) );
			$template->assign( 'menu_array', $menu_array );
			echo $template->parse( 'left.php' );
		}
	}

	$action = new action();
	$action->run();
?>